################################################################################
# pkcs11-hse
################################################################################

PKCS11_HSE_NAME := pkcs11-hse
PKCS11_HSE_VERSION := $(call qstrip,$(BR2_PACKAGE_S32_PKCS11_HSE_VERSION))
# 构建包名称
PKCS11_HSE_PKG = $(PKCS11_HSE_NAME)-$(PKCS11_HSE_VERSION)
PKCS11_HSE_SITE = package/nxp/s32/hse/pkcs11-hse/$(PKCS11_HSE_PKG)
PKCS11_HSE_SITE_METHOD = local

PKCS11_HSE_DEPENDENCIES += libp11 openssl hse-firmware

# 添加编译选项
PKCS11_HSE_MAKE_OPTS += \
    CROSS_COMPILE=$(TARGET_CROSS) \
    HSE_FWDIR=$(STAGING_DIR)/usr/include/hse-interface \
    OPENSSL_DIR=$(STAGING_DIR)/usr \
    LIBP11_DIR=$(STAGING_DIR)/usr

# 定义构建命令
define PKCS11_HSE_BUILD_CMDS
    $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(PKCS11_HSE_MAKE_OPTS)
endef

# 安装目标文件
define PKCS11_HSE_INSTALL_TARGET_CMDS
    $(INSTALL) -d $(TARGET_DIR)/usr/lib
    $(INSTALL) -d $(TARGET_DIR)/usr/bin
    $(INSTALL) -d $(TARGET_DIR)/usr/include

    $(MAKE) -C $(@D) install $(PKCS11_HSE_MAKE_OPTS) \
        INSTALL_LIBDIR=$(TARGET_DIR)/usr/lib \
        INSTALL_BINDIR=$(TARGET_DIR)/usr/bin \
        INSTALL_INCLUDEDIR=$(TARGET_DIR)/usr/include
endef

# 安装开发文件到 staging
PKCS11_HSE_INSTALL_STAGING = YES
define PKCS11_HSE_INSTALL_STAGING_CMDS
    $(INSTALL) -d $(STAGING_DIR)/usr/lib
    $(INSTALL) -d $(STAGING_DIR)/usr/bin
    $(INSTALL) -d $(STAGING_DIR)/usr/include

    $(MAKE) -C $(@D) install $(PKCS11_HSE_MAKE_OPTS) \
        INSTALL_LIBDIR=$(STAGING_DIR)/usr/lib \
        INSTALL_BINDIR=$(STAGING_DIR)/usr/bin \
        INSTALL_INCLUDEDIR=$(STAGING_DIR)/usr/include
endef

$(eval $(generic-package))
